package com.leeyu.rabbitmq.hello;

import com.leeyu.rabbitmq.util.RabbitMQConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;

import java.nio.charset.StandardCharsets;

public class Publisher {

    private static final String QUEUE_NAME = "hello";

    @Test
    public void publish() throws Exception {

        // 获取连接
        Connection connection = RabbitMQConnectionUtil.getConnection();

        // 构建channel
        Channel channel = connection.createChannel();

        // 构建队列
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);

        // 发布消息
        channel.basicPublish("", QUEUE_NAME, null, "Hello World!".getBytes(StandardCharsets.UTF_8));
        System.out.println("消息发送成功！");
    }
}
